<template>


		 <div style="height:100%;">
		    <el-scrollbar style="height:100%">
		        <div style="width:99%;height:100%;border:solid;" >
					
			<el-select style="padding: 10px;" v-model="tikuId" placeholder="请选择" @change="getTiMuList(tikuId)">
				<el-option v-for="item in tikuList" :key="item.id" :label="item.name" :value="item.id">
				</el-option>
			</el-select>
			<el-button v-if="tikuId" @click="xzst()">新增题目</el-button>
			<div>
				<el-table :data="tableData" style="width: 100%">
					<el-table-column prop="type" label="题目类型">
					</el-table-column>
					<el-table-column  v-html="tableData.timu" label="题目内容">
						<template slot-scope="scope">
							<span v-html="scope.row.timu"></span>
						</template>
					</el-table-column>
					<el-table-column prop="zhishi.name" label="知识点">
					</el-table-column>
					
					<el-table-column fixed="right" label="操作">
						<template slot-scope="scope">
								<el-button @click="edita(scope.row)" type="text" size="small">修改试题内容</el-button>
							<el-button @click="deletea(scope.row)" type="text" size="small">删除</el-button>
						</template>
					</el-table-column>
				</el-table>
			</div>
			  </div>
			    </el-scrollbar>
			  </div>


</template>

<script>
	export default {
		data() {
			return {
				tikuList: [],
				tikuId: '',
				tableData: []
			}
		},
		methods: {
			edita(row){
				window.sessionStorage.setItem("shiti",JSON.stringify(row));
				this.xzst();
			},
			deletea(row) {
				this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					this.$ajax.post("/question/delete1", {
						"id": row.id
					}).then(res => {
						if (res.data.success) {
							this.$message.success(res.data.msg)
							this.getTiMuList(this.tikuId)
						} else {
							this.$message.error(res.data.msg)
						}
					})
				}).catch(() => {
					
				});


			},
			getTikuList() {
				this.$ajax.post("/tiku/list", {}).then(res => {
					var result = res.data
					this.tikuList = result.data
				})
			},
			xzst() {
				this.$router.push('/exam/index?tikuId=' + this.tikuId)
			},
			getTiMuList(tikuId) {
				this.$ajax.post("/tiku/timulist", {
					"tikuId": tikuId
				}).then(res => {
					var result = res.data.data
					for (let i = 0; i < result.length; i++) {
						if (result[i].type == 1) {
							result[i].type = "单选题"
						} else if (result[i].type == 2) {
							result[i].type = '多选题'
						} else {
							result[i].type = "判断题"
						}
					}
					this.tableData = result
				})
			},
		},
		created() {
			this.getTikuList()
			window.sessionStorage.removeItem("shiti")
		}
	}
</script>

<style>
</style>
